package impl

import (
	"adam2/internal/vo"
	pConstants "anubis-framework/pkg/constants"
	pDomain "anubis-framework/pkg/domain"
	"anubis-framework/pkg/util"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ConceptBoardIndexControllerImpl struct {
	*BaseControllerImpl
}

// 获取ConceptBoardIndexControllerImpl
func GetConceptBoardIndexControllerImpl() *ConceptBoardIndexControllerImpl {
	return &ConceptBoardIndexControllerImpl{GetBaseControllerImpl()}
}

// 获取最近记录
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) FindLatestConceptBoardIndex(c *gin.Context) {
	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.FindLatestConceptBoardIndex()
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}

// 查询前一个交易日的日期
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) PreviousTransactionDate(c *gin.Context) {
	var transactionDate string = c.Param("transactionDate")

	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.PreviousDate(transactionDate)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}

// 查询后一个交易日的日期
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) NextTransactionDate(c *gin.Context) {
	var transactionDate string = c.Param("transactionDate")

	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.NextTransactionDate(transactionDate)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}

// 根据开始时间和结束时间，计算平均KD值
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) FindAverageKDByBeginDateAndEndDate(c *gin.Context) {
	// 转换参数
	var kdVo *vo.KDVo = &vo.KDVo{}
	c.BindJSON(kdVo)

	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.FindAverageKDByBeginDateAndEndDate(kdVo)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}

// 根据开始时间和结束时间，查询某个概念板块的KD值
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) FindKdByMyquantCodeAndBeginDateAndEndDate(c *gin.Context) {
	// 转换参数
	var kdVo *vo.KDVo = &vo.KDVo{}
	c.BindJSON(kdVo)

	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.FindKdByMyquantCodeAndBeginDateAndEndDate(kdVo)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}

// 根据myquant_code、begin_date和end_date，查询记录，并按照transaction_date列升序排列
func (_conceptBoardIndexControllerImpl *ConceptBoardIndexControllerImpl) FindByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc(c *gin.Context) {
	// 转换参数
	var findConceptBoardIndexVo *vo.FindConceptBoardIndexVo = &vo.FindConceptBoardIndexVo{}
	c.BindJSON(findConceptBoardIndexVo)

	// 参数验证：参数beginDate和endDate不能为空
	if findConceptBoardIndexVo.BeginDate == "" || findConceptBoardIndexVo.EndDate == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数beginDate和endDate不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 参数验证：参数myquantCode不能为空
	if findConceptBoardIndexVo.MyquantCode == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数myquantCode不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	var serviceResult *pDomain.ServiceResult = _conceptBoardIndexControllerImpl._conceptBoardIndexServiceImpl.FindByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc(findConceptBoardIndexVo)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}
